<template>
    <!-- <div class="app-container"> -->
      <div class="main-class">
      <el-row :gutter="20">
        <el-col :span="24" :xs="24">
        </el-col>
   
        </el-row>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
          >删除</el-button>
        </el-col>

   
      
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>

        <el-table v-loading="loading" :data="categoryList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="司机姓名" align="center" prop="name" />
      <el-table-column label="手机号码" align="center" prop="phoneNumber" />
      <el-table-column label="车牌号" align="center" prop="carNumber" />
      <el-table-column label="驾照号" align="center" prop="licenseNumber" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <Pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
        />

      </el-row>
  
   
   
  
     <!-- 添加或修改司机对话框 -->
     <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="司机姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入司机姓名" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="车牌号" prop="carNumber">
          <el-input v-model="form.carNumber" placeholder="请输入车牌号" />
        </el-form-item>
        <el-form-item label="驾照号" prop="licenseNumber">
          <el-input v-model="form.licenseNumber" placeholder="请输入驾照号" />
        </el-form-item>
        <!-- <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    </div>
  </template>
  
  <script>

  export default {
    name: "Driver",
    // dicts: ['sys_normal_disable'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 生活服务信息表格数据
        categoryList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
          // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          id: null,
          name: null,
          phoneNumber: null,
          carNumber: null,
          licenseNumber: null,
          status: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          name: [
          { required: true, message: "司机姓名不能为空", trigger: "blur" }
        ],
        phoneNumber: [
          { required: true, message: "手机号码不能为空", trigger: "blur" }
        ],
        carNumber: [
          { required: true, message: "车牌号不能为空", trigger: "blur" }
        ],
        licenseNumber: [
          { required: true, message: "驾照号不能为空", trigger: "blur" }
        ],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询生活服务信息列表 */

      getList(){
                this.loading = true
                this.$axios.get("/system/driver/list", {params: {

                  category: this.queryParams.category,
                  providerName: this.queryParams.providerName,
                  description: this.queryParams.description,
                  price: this.queryParams.price,
                  address: this.queryParams.address,
                  pageNum: this.queryParams.pageNum,
                  pageSize: this.queryParams.pageSize

      
                    }}).then(res => {
                    this.categoryList = res.data.data.records
                    this.total = res.data.data.total
                    this.loading = false
                })
            },

 
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
        id: null,
        name: null,
        phoneNumber: null,
        carNumber: null,
        licenseNumber: null,
        status: 0
        };
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.getList();
        this.queryParams = {
                    pageNum: 1,
                    pageSize: 10,
                    name: null,
                    phoneNumber: null,
                    carNumber: null,
                    licenseNumber: null,
                    status: 0
                },
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd(row) {
                this.reset();
                if (row !== undefined) {
                    this.form.id = row.id;
                }
                this.open = true;
                this.title = "添加生活服务信息";
            },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        this.$axios.get("/system/driver/" + id).then(response => {
          this.form = response.data.data;
          this.open = true;
          this.title = "修改生活服务信息";
        });
      },
      /** 提交按钮 */
      submitForm: function() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id !== undefined) {
                            this.$axios.put("/system/driver", this.form).then(res => {
                                if (res.data.code === 200){
                                    this.modal.notifySuccess(res.data.data)
                                }
                                this.getList()
                            })
                        } else {
                            this.$axios.post("/system/driver", this.form).then(res => {
                                if (res.data.code === 200){
                                    this.modal.notifySuccess(res.data.data)
                                }
                                this.getList()
                            })
                        }
                    }
                });
                this.open = false
            },
      /** 删除按钮操作 */
      handleDelete(row){
                const ids = row.id || this.ids
                if (ids.length > 1 && ids.indexOf(1) !== -1){
                    this.modal.notifyWarning("不可以删除信息")
                }else{
                    this.modal.confirm('是否确认删除信息？').then(function () {
                    }).then(()=>{
                        this.$axios.delete("/system/driver?ids=" + ids).then(res => {
                            if (res.data.code === 200){
                                this.modal.notifySuccess(res.data.data)
                                this.getList()
                            }
                        })
                    }).catch(()=>{
                        this.getList()
                    })
                }

            },
       
    
    }
  };
  </script>
  